﻿define([
    'require',
    'angular',
    'underscore'
], function (require, angular, _) {
    return function ($scope, $routeParams, $http, RuleSerivce,$dataSourceManager,$timeout,GillionMsg,GillionMsgService,Resource) {

        RuleSerivce.promises().then(function () {
            $scope.groupId = $scope.currPackage.groupId;
            $scope.artifactId = $scope.currPackage.artifactId;
            $scope.versionParams={
                groupId:$scope.groupId,
                artifactId:$scope.artifactId
            }
            $timeout(function(){
                $dataSourceManager.dataSources["VersionSource"].params = $scope.versionParams;
                $dataSourceManager.dataSources["VersionSource"].doRequestData();
            },100);
        });

        /*$scope.$on("VersionSource", function (context, dataSource) {
            if (dataSource.records) {
                $scope.unitcases =dataSource.records.data;
            }
        });*/

        $scope.hisPublish= function(row){
            if (row.status == 1) {
                GillionMsg.alert('提示', '该版本已经是发布！');
                return;
            }
            Resource("/grule-manager/rulePackage/publish/:id", {
                id: "@id"
            }, {
                "get": {
                    "failHandler": false
                }
            }).update({
                id: row.id
            }, function (response) {
                if (response.success) {
                    GillionMsg.alert('提示消息', '发布成功！', function(){
                        var param = {};
                        param.groupId=$scope.groupId;
                        param.artifactId=$scope.artifactId;
                        $dataSourceManager.dataSources["VersionSource"].params = param;
                        $dataSourceManager.dataSources["VersionSource"].doRequestData();
                        GillionMsgService.close();
                    });
                }
            });
        }

        $scope.hisVersion= function(row){
            RuleSerivce.setCurrentPackage(row);
            window.location.href="../html2/home#/projects/"+row.projectid+"/packages/"+row.id;
        }
    };
});